<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<%@ taglib uri="/WEB-INF/tld/security.tld" prefix="s" %>
<fmt:setBundle basename="messages"/>

<script type="text/javascript" language="javascript">
	var validSubmit = true;
	function submitEditTransport(form, transportId){
		
		if (validSubmit){
			document.getElementById('selectedTransport').value = transportId;
			form.action = 'showEditTransport.do';
			validSubmit = false;
			
			form.submit();
		} else {
			alert('<fmt:message key="warning.message.common.processing"/>');
		}
	}

	function submitDeleteTransport(form, transportId,shortName){
		if(confirmDelete(shortName)){
			if (validSubmit){
				document.getElementById('selectedTransport').value = transportId;
				form.action = 'deleteTransport.do';
				validSubmit = false;
				
				form.submit();
			} else {
				alert('<fmt:message key="warning.message.common.processing"/>');
			}
		}
	}

	function submitTransportsQuery(form, orderField, orderType){
		form.orderField.value = orderField;
		form.orderType.value = orderType;
		form.action = "showTransportQuery.do";

		if (validSubmit){
			form.submit();
		} else {
			alert('<fmt:message key="warning.message.common.processing"/>');
		}
	}
</script>

<table width="100%">
	<tr>
		<td>
			<form name="TransportQueryForm" method="POST">
				<input type="hidden" name="id" id="selectedTransport"/>
				<input type="hidden" name="orderField"/>
				<input type="hidden" name="orderType"/>
				<table align="center" width="60%" cellpadding="2" cellspacing="1" border="0" bgcolor="#CCCCC0">
					<tr>
						<td class="titulocolumna" align="center">
						  <s:entidad nombreCortoMod="CATALOG" nombreCortoSub="TRANS" nombreCortoEnt="NEW" permiso="ADMINISTRACION"> 	
							<a href="createNewTransport.do">
								<img alt="<fmt:message key="common.add"/> <fmt:message key="label.transports.query.transport"/>" src="images/nuevo.gif" border="0"/>
							</a>
							</s:entidad>
						</td>
						<td class="titulocolumna" align="center">
							<a href="#>" onclick="submitTransportsQuery(TransportQueryForm, 1, '<c:choose><c:when test="${previousOrderField == 1 && previousOrderType == 0}">1</c:when><c:otherwise>0</c:otherwise></c:choose>');"class="ligas">
								<fmt:message key="label.transports.query.transport"/>
								<c:choose>
									<c:when test="${previousOrderField == 1 && previousOrderType == 1}">
										<img alt="<fmt:message key="label.common.order.ascending"/>" src="images/arrow_up.gif" border="0"/>
									</c:when>
									<c:when test="${previousOrderField == 1 && previousOrderType == 0}">
										<img alt="<fmt:message key="label.common.order.descending"/>" src="images/arrow_down.gif" border="0"/>
									</c:when>
								</c:choose>
							</a>
						</td>
						<td class="titulocolumna" align="center">
							<a href="#>" onclick="submitTransportsQuery(TransportQueryForm, 2, '<c:choose><c:when test="${previousOrderField == 2 && previousOrderType == 0}">1</c:when><c:otherwise>0</c:otherwise></c:choose>');"class="ligas">
								<fmt:message key="label.transports.query.description"/>
								<c:choose>
									<c:when test="${previousOrderField == 2 && previousOrderType == 1}">
										<img alt="<fmt:message key="label.common.order.ascending"/>" src="images/arrow_up.gif" border="0"/>
									</c:when>
									<c:when test="${previousOrderField == 2 && previousOrderType == 0}">
										<img alt="<fmt:message key="label.common.order.descending"/>" src="images/arrow_down.gif" border="0"/>
									</c:when>
								</c:choose>
							</a>
						</td>
						<td class="titulocolumna" align="center">
							<a href="#>" onclick="submitTransportsQuery(TransportQueryForm, 3, '<c:choose><c:when test="${previousOrderField == 3 && previousOrderType == 0}">1</c:when><c:otherwise>0</c:otherwise></c:choose>');"class="ligas">
								<fmt:message key="label.common.corntype"/>
								<c:choose>
									<c:when test="${previousOrderField == 3 && previousOrderType == 1}">
										<img alt="<fmt:message key="label.common.order.ascending"/>" src="images/arrow_up.gif" border="0"/>
									</c:when>
									<c:when test="${previousOrderField == 3 && previousOrderType == 0}">
										<img alt="<fmt:message key="label.common.order.descending"/>" src="images/arrow_down.gif" border="0"/>
									</c:when>
								</c:choose>
							</a>
						</td>
						<td class="titulocolumna" align="center">
							<a href="#>" onclick="submitTransportsQuery(TransportQueryForm, 4, '<c:choose><c:when test="${previousOrderField == 4 && previousOrderType == 0}">1</c:when><c:otherwise>0</c:otherwise></c:choose>');"class="ligas">
								<fmt:message key="label.transports.query.nomenclature"/>
								<c:choose>
									<c:when test="${previousOrderField == 4 && previousOrderType == 1}">
										<img alt="<fmt:message key="label.common.order.ascending"/>" src="images/arrow_up.gif" border="0"/>
									</c:when>
									<c:when test="${previousOrderField == 4 && previousOrderType == 0}">
										<img alt="<fmt:message key="label.common.order.descending"/>" src="images/arrow_down.gif" border="0"/>
									</c:when>
								</c:choose>
							</a>
						</td>
						<td class="titulocolumna" align="center">
							<a href="#>" onclick="submitTransportsQuery(TransportQueryForm, 5, '<c:choose><c:when test="${previousOrderField == 5 && previousOrderType == 0}">1</c:when><c:otherwise>0</c:otherwise></c:choose>');"class="ligas">
								<fmt:message key="label.transports.query.capacity"/>
								<c:choose>
									<c:when test="${previousOrderField == 5 && previousOrderType == 1}">
										<img alt="<fmt:message key="label.common.order.ascending"/>" src="images/arrow_up.gif" border="0"/>
									</c:when>
									<c:when test="${previousOrderField == 5 && previousOrderType == 0}">
										<img alt="<fmt:message key="label.common.order.descending"/>" src="images/arrow_down.gif" border="0"/>
									</c:when>
								</c:choose>
							</a>
						</td>
						<td class="titulocolumna" align="center">
							<a href="#>" onclick="submitTransportsQuery(TransportQueryForm, 6, '<c:choose><c:when test="${previousOrderField == 6 && previousOrderType == 0}">1</c:when><c:otherwise>0</c:otherwise></c:choose>');"class="ligas">
								<fmt:message key="label.transports.query.priority"/>
								<c:choose>
									<c:when test="${previousOrderField == 6 && previousOrderType == 1}">
										<img alt="<fmt:message key="label.common.order.ascending"/>" src="images/arrow_up.gif" border="0"/>
									</c:when>
									<c:when test="${previousOrderField == 6 && previousOrderType == 0}">
										<img alt="<fmt:message key="label.common.order.descending"/>" src="images/arrow_down.gif" border="0"/>
									</c:when>
								</c:choose>
							</a>
						</td>
						<td class="titulocolumna" align="center">
							<a href="#>" onclick="submitTransportsQuery(TransportQueryForm, 7, '<c:choose><c:when test="${previousOrderField == 7 && previousOrderType == 0}">1</c:when><c:otherwise>0</c:otherwise></c:choose>');"class="ligas">
								<fmt:message key="label.transports.query.pricePerCornUnit"/>
								<c:choose>
									<c:when test="${previousOrderField == 7 && previousOrderType == 1}">
										<img alt="<fmt:message key="label.common.order.ascending"/>" src="images/arrow_up.gif" border="0"/>
									</c:when>
									<c:when test="${previousOrderField == 7 && previousOrderType == 0}">
										<img alt="<fmt:message key="label.common.order.descending"/>" src="images/arrow_down.gif" border="0"/>
									</c:when>
								</c:choose>
							</a>
						</td>
						<td class="titulocolumna" align="center">&nbsp;</td>
					</tr>
					<c:forEach items="${transportList}" var="transport" varStatus="status">
						<tr class="<c:choose><c:when test="${status.index%2 == 0}"><c:out value="columnadatoPar" /></c:when><c:otherwise><c:out value="columnadatoNon" /></c:otherwise></c:choose>">
							<td valign="top" align="center">
								<s:entidad nombreCortoMod="CATALOG" nombreCortoSub="TRANS" nombreCortoEnt="EDIT" permiso="ADMINISTRACION">
									<a href="#>" onclick="submitEditTransport(TransportQueryForm, '<c:out value="${transport.transportIdentifier}"/>');">
										<img alt="<fmt:message key="common.edit"/> <c:out value="${transport.transportShortName}"/>" src="images/modificar.gif" border="0"/>
									</a>
								</s:entidad>	
							</td>
							<td valign="top" align="center">
								<c:out value="${transport.transportShortName}"/>
							</td>
							<td valign="top" align="center">
								<c:out value="${transport.transportDescription}"/>
							</td>
								<td valign="top" align="center">
								<c:out value="${transport.cornTypesView.description}"/>
							</td>
							<td valign="top" align="center">
								<c:out value="${transport.transportNomenclature}"/>
							</td>
							<td valign="top" align="right">
								<c:if test="${transport.transportCapacity != 0.0}">
									<fmt:formatNumber pattern="###,###,##0.000" type="number" maxFractionDigits="3" minFractionDigits="3" value="${transport.transportCapacity}"/>
								</c:if>
							</td>
							<td valign="top" align="right">
								<c:out value="${transport.transportPriority}"/>
							</td>
							<td valign="top" align="right">
								<c:if test="${transport.totalCost != 0.0}">
									<fmt:formatNumber pattern="###,###,##0.0000" type="number" maxFractionDigits="4" value="${transport.totalCost}" />
								</c:if>
							</td>
							<td>
								<s:entidad nombreCortoMod="CATALOG" nombreCortoSub="TRANS" nombreCortoEnt="DELETE" permiso="ADMINISTRACION">
									<a href="#>" onclick="submitDeleteTransport(TransportQueryForm, '<c:out value="${transport.transportIdentifier}"/>','<c:out value="${transport.transportShortName}"/>');">
										<img alt="<fmt:message key="common.delete"/> <c:out value="${transport.transportShortName}"/>" src="images/eliminar.jpg" border="0"/>
									</a>
								</s:entidad>	
							</td>
						</tr>
					</c:forEach>
				</table>
			</form>
		</td>
	</tr>
</table>
<br />
<br />